1. /* sxmsetdb.cpp by K.Tsuru */
  2. // function ID = 501 BRADIX
  3. #ifndef SN_H
  4. #include "sn.h"
  5. #endif
  6. /*************************************************************
  7. SDecimal class
  8. Provides a radix conversion
  9. double ---> BRADIX
  10. Used in the substitution of double type including long type.
  11. *************************************************************/
  12. void SDecimal::SetXDouble(double d){
  13. if(d == 0.0){
  14. SetZero(); return;
  15. }
  16. /***************************************************************************
  17. A finite binary decimal such as ldexp(1.5, -400) = 1.5*2^(-400) must be
  18. converted exactly.If this is treated in the decimal radix(DRADIX) an
  19. inacurate value is supplied because of taiking into account fifteen
  20. effective figures only.On the other hand if an infinite binary decimal such
  21. as 0.1 are converted to a binary decimal in 53 bits it may be contrary to
  22. user's expectations.In this case it converts once the value into DRADIX,
  23. next into BRADIX.
  24. A decimal ldexp(f, -400) whose f has more than 30 bits cannot be converted
  25. exactly? It is difficult to judge whether it must be converted into infinite
  26. or finite decimal.
  27. ***************************************************************************/
  28. uint sz;
  29. //Convert |d| into a value with binary radix(BRADIX). This can be performed
  30. //exactly for any value.
  31. int bfig = DOUBLE_BITS/BRADIX_BITS; // = 53bits/15 = 3.5figures
  32. int f = doubleToBinDec(fabs(d), figure, &sz);
  33. if(f < 0) SetError(OVERFLOW_ERR, "SetXDouble",501);
  34. if(f < bfig){//within two figures in BRADIX(30bits) for safety.
  35. // |d| = I.abcd efgh 0000 abcd efgh .... can be existent.
  36. aTail = 0;
  37. sz = min(sz, MaxSize());
  38. while( (figure(aTail)== 0) && (aTail < sz) ) aTail++;
  39. // d is very small and can be regarded as zero within present accuracy.
  40. if(aTail == sz){
  41. SetZero(); return;
  42. }
  43. aHead = sz-1u; while(figure(aHead)== 0) aHead--;
  44. SetSign(d);
  45. return;
  46. }
  47. //Here it may be an infinite decimal in BRADIX.
  48. SDouble a(d); //convert into DRADIX
  49. SDecimal tmp; // Changes called by object since version 2.20
  50. *this = tmp.ConvToBin(a); //convert into BRADIX
  51. }

sxmsetdb.cpp : last modifiled at 2015/12/15 14:05:33(2,143 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).